﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Trans.car
{
    public partial class Add_maintain : Form
    {
        DataRowView row;
        public Add_maintain()
        {
            InitializeComponent();
        }

        private void Add_maintain_Load(object sender, EventArgs e)
        {
            row=(DataRowView)tbmaintainBindingSource.AddNew();
        }

        private void bt_car_Click(object sender, EventArgs e)
        {
            Select_car f = new Select_car();
            f.ShowDialog();
            if(f.HasSelected)
            {
                row["car_id"]=f.Id;
                lb_car.Text = f.CarLicense;
            }
        }

        private void bt_add_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
            {
                try
                {
                    row["oper_id"] = session.Oper.id;
                    tbmaintainBindingSource.EndEdit();
                    tb_maintainTableAdapter.Update(dataSet.tb_maintain);
                    this.Close();
                    MessageBox.Show("添加成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("出错啦" + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
           
        }

        private void bt_cancel_Click(object sender, EventArgs e)
        {
            tbmaintainBindingSource.CancelEdit();
            this.Close();
        }
    }
}
